1
|
|
|
/** |
2
|
|
|
sidebar |
3
|
|
|
Simple component to display the resource sidebar. |
4
|
|
|
|
5
|
|
|
@namespace Components |
6
|
|
|
*/ |
7
|
|
|
'use strict'; |
8
|
|
|
|
9
|
|
|
angular.module('game').component('sidebar', { |
10
|
|
|
templateUrl: 'views/sidebar.html', |
11
|
|
|
controller: ['state', 'visibility', 'data', 'format', 'util', sidebar], |
12
|
|
|
controllerAs: 'ct' |
13
|
|
|
}); |
14
|
|
|
|
15
|
|
|
function sidebar(state, visibility, data, format, util) { |
16
|
|
|
let ct = this; |
17
|
|
|
ct.state = state; |
18
|
|
|
ct.data = data; |
19
|
|
|
ct.format = format; |
20
|
|
|
ct.util = util; |
21
|
|
|
|
22
|
|
|
// returns the elements selected plus empty string '' |
23
|
|
|
// '' represents misc resources and it is always 'active' |
24
|
|
|
ct.activeElements = function(player) { |
25
|
|
|
let result = []; |
26
|
|
|
for(let slot of player.element_slots) { |
27
|
|
|
if(slot){ |
28
|
|
|
result.push(slot.element); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
result.push(''); |
32
|
|
|
return result; |
33
|
|
|
}; |
34
|
|
|
|
35
|
|
|
ct.visibleResources = function(element, player) { |
36
|
|
|
return visibility.visible(data.resources, isResourceVisible, element, null, player); |
37
|
|
|
}; |
38
|
|
|
|
39
|
|
|
function isResourceVisible(name, currentElement, player) { |
40
|
|
|
if (player.resources[name] === null) { |
41
|
|
|
return false; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// This is for global resources e.g. protons, which do not |
45
|
|
|
// belong to any element |
46
|
|
|
let elements = data.resources[name].elements; |
47
|
|
|
if (Object.keys(elements).length === 0 && currentElement === '') { |
48
|
|
|
return true; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
for (let element in elements) { |
52
|
|
|
if (currentElement === element && |
53
|
|
|
(player.statistics.exotic_run[element] && |
54
|
|
|
typeof player.statistics.exotic_run[element][name] !== 'undefined' || |
55
|
|
|
data.elements[element].exotic === name)) { |
56
|
|
|
return true; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return false; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|